# -*- coding: utf-8 -*-
"""
Created on Thu Sep 19 10:53:19 2019

@author: Administrator
"""

# 1022 D进制A+B
# 任意进制转换：一个循环的短除求余的过程
"""
def test():
    data = str(input()).split(' ')
    if len(data) != 3:
        return
    a = int(data[0])
    b = int(data[1])
    system = int(data[2])
    
    if a < 0 or b < 0 or system > 10 or system <= 1:
        return
    
    result = a + b
    
    print(switch_system(result, system))
    
def switch_system(data, system):
    result_list = []

    if data == 0:
        return 0
    
    while data != 0:
        remainder = data % system
        result_list.append(remainder)
        data = data // system
        
    result_list.reverse()
    result_list = [str(ele) for ele in result_list]
    return int("".join(result_list))

#print(switch_system(101, 5))
test()
"""